<!--编辑/添加故障-->
<div class="dialog_content">
	<form id="info_form" action="{:U('fault/oppt')}" method="post">
    <input type="hidden" name="opttype" value="{$type}" />
    <input type="hidden" name="faultType" value="{$faultType}" />
	<table width="100%" class="table_form">
		<tr>
			<th>{:L('please_select')}{:L('store')} :</th>
			<td>           
                <select class="J_cate_select mr10" data-pid="0" data-uri="{:U('region/ajax_getchilds',array('type'=>'store'))}" data-selected="{$info.selected_ids}"></select>
                <input type="hidden" name="regionId" id="J_cate_id" value="{$search.cate_id}" />                 
            </td>
		</tr>
	    <tr>
        <if condition="$faultType eq 'modelFault'">
		<tr>
			<th>请选择品牌 :</th>
			<td>
                <select name="brandId" id="brand_select_add">
                    <option value="">请选择品牌</option>
                    <volist name="brandList" id="item">
                        <option value="{$key}">{$item}</option>
                    </volist>
                </select>
            </td>
		</tr>
	    <tr>        
			<th>请选择机型 :</th>
			<td>
                <select name="modelId" id="model_select_add">
                    <option value="0">{:L('please_select_brand')}</option>
                    
                </select> 
			</td>
		</tr>  
 	    <tr>
			<th>IMEI :</th>
			<td>
		         <input type="text" class="input-text" name="imei" value="{$info.imei}" />
			</td>
		</tr> 
        </if>
 	    <tr>
			<th>故障描述 :</th>
			<td>
		         <textarea name="remark" id="remark">{$info.remark}</textarea>
			</td>
		</tr>         
  	    <tr>
			<th>图片上传 :</th>
			<td>
                 <div style="float: left;" id="photo_list">
                    <input type="file" name="phoot[]" />
                 </div>
		         <div style="float: left;">
                    <a id="add_photo" href="javascript:void(0);">增加图片</a>
                 </div>
			</td>
		</tr>                         
        <!--类型属性-->
        
        
	</table>
	<input type="hidden" name="id" value="{$info.id}" />
	</form>
</div>
<script src="__STATIC__/js/fileuploader.js"></script>
<script>
$(function(){
	$.formValidator.initConfig({formid:"info_form",autotip:true});
	
	$('#info_form').ajaxForm({success:complate,dataType:'json'});
	function complate(result){
		if(result.status == 1){
			$.dialog.get(result.dialog).close();
            $.pinphp.tip({content:result.msg});
            window.location.reload();
		} else {
			$.pinphp.tip({content:result.msg, icon:'alert'});
		}
	}
   	var check_name_url = "{:U('fault/getAttribute',array('faultType'=>$faultType))}";
    $.ajax({url:check_name_url,dataType:'json',success:function(attrList){
        var str = '';
        attrList = attrList['data'];        
        for(i in attrList){
            //alert(i);
            str +='<tr><th>'+attrList[i]['name']+'</th><td>';
            str +=makeStr(attrList[i]['rules']['choices'],attrList[i]['type'],attrList[i]['id'],i);
            str +='</td></tr>';
        }
        $('.table_form').append(str);
            
        // select  属性有多级分类的时候，暂时只支持 两级分类。    
        $(".choices_select").live('change',function(){
            var _this = $(this);
            _this.nextAll('.choices_select').remove();
            //取当前值
            var v = _this.val();
            var attr_id = _this.attr('attr_id'); 
            //alert(attr_id);
            //取 当前属性的ID
            var pid = attrList[attr_id+""]['id'];
            var str = '';
            if(attrList[attr_id]['rules']['choices'][v]!=undefined){
                var child = attrList[attr_id]['rules']['choices'][v]['child'];
            
                str +='<select attr_id="'+attr_id+'" class="choices_select">  <option value="">请选择</option>';
                for(c in child){
                    str +='<option date-key="'+c+'" value="'+child[c]['value']+'">'+child[c]['txt']+'</option>';
                }  
                str +='</select>'; 
                _this.after(str);
            }           
            $("#choices_"+pid).val(v);
        });   
    }})
    
    // 生成html 
    function makeStr(child,type,pid,attr_id){       
        if(child==undefined){
            child = {};
        }           
        var str = '';      
        switch(type){
            case "select":
                str +='<select attr_id="'+attr_id+'" class="choices_select"> <option value="">请选择</option>';
                for(i in child){
                    str +='<option date-key="'+i+'" value="'+child[i]['value']+'">'+child[i]['txt']+'</option>';
                }  
               str +='</select>'; 
               str +='<input type="hidden" name="choices['+pid+']" id="choices_'+pid+'" value="" />';
               break; 
            case "text":
            case "number":
               str +='<input type="text" name="choices['+pid+']" />';   
                break;
            case "radio":  
            case "checkbox":               
               for(i in child){
                    str +='<label><input name="choices['+pid+'][]" type="'+type+'" value="'+child[i]['value']+'" />'+child[i]['txt']+'</label>';
               }
        } 
       return str; 
       
    }
    
$('.J_cate_select').cate_select();   

$("#brand_select_add").change(function(){
   var _this = $(this);
   var brand_id = _this.val();
   var ajax_get_region = "{:U('model/getModelList')}";
   if(brand_id){
    $.ajax({
        url:ajax_get_region,
        data:"brand_id="+brand_id,
        dataType:"json",
        success:function(data){
            if(data.status==1){
                var str = '<option value="0">'+lang.please_select+'</option>';
                for(d in data.data){
                    str +='<option value="'+d+'">'+data['data'][d]+'</option>';
                }
                $("#model_select_add").html(str);
            }
        }
    });        
   }else{
        $("#model_select_add").empty();
   }                
    
}); 

//多图片上传
$("#add_photo").click(function(){
   $("#photo_list").append('<br/><input type="file" name="phoot[]" />'); 
});

});

</script>